package com.qidian.controller;

import com.qidian.pojo.Bank;
import com.qidian.service.BankService;
import com.qidian.util.BankResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author 戴着假发的程序员
 * @company 江苏极刻知学-起点编程
 */
@RestController
public class BankController {
    @Autowired
    private BankService bankService;

    @RequestMapping("/bank-save")
    public BankResult bankSave(Bank bank){
        return bankService.save(bank);
    }
    // 我们使用的前端框架传递的页码参数名称为pate，每页大小的参数名称为limit
    @RequestMapping("/bank-list")
    public Map bankList(String bankName, @RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int limit){
        return  bankService.queryByPage(bankName,page,limit);
    }

    @RequestMapping("/bank-all")
    public List<Bank> queryAll(){
        return bankService.queryAll();
    };


    @RequestMapping("/query/{bankId}/bank")
    public Bank queryById(@PathVariable Integer bankId){
        return bankService.queryById(bankId);
    };

    @RequestMapping("/bank-edit")
    public BankResult edit(Bank bank){
        return bankService.update(bank);
    }

    @RequestMapping("/delete/{bankId}/bank")
    public BankResult delete(@PathVariable int bankId){
        return bankService.delete(bankId);
    };

    @RequestMapping("/delete-bank")
    public BankResult delete(Integer [] bankIds){
        return bankService.delete(Arrays.asList(bankIds));
    };
}
